package sort;

import java.util.Arrays;

/**
 * Created by Administrator on 2018/2/27 0027.
 */
public class BubbleSort
{
    public static void main(String[] args)
    {
        int[] NUMBERS = {49, 38, 65, 12};// 97, 76, 13, 27, 78, 34, 12, 64, 5, 4, 62, 99, 98, 54, 56, 17, 18, 23, 34, 15, 35, 25, 53, 51};
        sort(NUMBERS);
        System.out.println(Arrays.toString(NUMBERS));
    }

    private static void sort(int[] src)
    {
        int tmp = 0;
        boolean hasChanged = false;
        for (int i = 0; i < src.length - 1; i++)
        {
            for (int j = 0; j < src.length - i - 1; j++)
            {
                if(src[j] > src[j +1])
                {
                    tmp = src[j+1];
                    src[j+1] = src[j];
                    src[j] = tmp;
                    hasChanged = true;
                }
            }
            if(!hasChanged)
            {
                System.out.println("进来了");
                return;
            }
            hasChanged = false;
        }
    }
}
